package br.com.edoc.entidade;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import br.com.edoc.enun.util.TipoEmail;



@Entity
@Table (name="PESSOA")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="PES_IDDOOBJETO")
public class Pessoa implements EntidadePadrao {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1936987352438249530L;
	@Id  
	@Column(name = "PES_IDDOOBJETO", nullable = false)  
	@GeneratedValue(strategy=GenerationType.IDENTITY)  
	private Integer id;
	@Column(name = "PES_DESCRICAO", nullable = false, length=50)
	private String descricao;
	@Temporal(TemporalType.DATE)
	@Column(name = "PES_DATACADASTRO", nullable = false, length=50)
	private Date dataCadastro;
	@OneToMany(mappedBy="pessoa",orphanRemoval=true,cascade={CascadeType.ALL})	
	private List<Email> listaEmails;
	@Transient
	private Email emailProfissional;
	@OneToMany(mappedBy="pessoa",orphanRemoval=true,cascade={CascadeType.ALL})	
	private List<Telefone> listaTelefones;
	@OneToMany(mappedBy="pessoa",orphanRemoval=true,cascade={CascadeType.ALL})	
	private List<Endereco> listaEndereco;
	@Transient
	private Endereco enderecoCorrespondencia;
	@Transient
	private Telefone celular;
	@Transient
	private Telefone telefoneResidencial;
	@Transient
	private Email emailInstitucional;
	
	
		
	@Override
	public Integer getId() {
		// TODO Auto-generated method stub
		return id;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getDataCadastro() {
		return dataCadastro;
	}

	public void setDataCadastro(Date dataCadastro) {
		this.dataCadastro = dataCadastro;
	}

	public List<Email> getListaEmails() {
		if(listaEmails == null){
			listaEmails = new ArrayList<Email>();
		}
		return listaEmails;
	}

	public void setListaEmails(List<Email> listaEmails) {
		this.listaEmails = listaEmails;
	}

	public List<Telefone> getListaTelefones() {
		if(listaTelefones == null){
			listaTelefones = new ArrayList<Telefone>();
		}
		return listaTelefones;
	}

	public void setListaTelefones(List<Telefone> listaTelefones) {
		this.listaTelefones = listaTelefones;
	}

	public List<Endereco> getListaEndereco() {
		if(listaEndereco == null){
			listaEndereco = new ArrayList<Endereco>();
		}
		return listaEndereco;
	}

	public void setListaEndereco(List<Endereco> listaEndereco) {
		this.listaEndereco = listaEndereco;
	}

	public Endereco getEnderecoCorrespondencia() {
		return enderecoCorrespondencia;
	}

	public void setEnderecoCorrespondencia(Endereco enderecoCorrespondencia) {
		this.enderecoCorrespondencia = enderecoCorrespondencia;
	}

	public Telefone getCelular() {
		return celular;
	}

	public void setCelular(Telefone celular) {
		this.celular = celular;
	}

	public Telefone getTelefoneResidencial() {
		return telefoneResidencial;
	}

	public void setTelefoneResidencial(Telefone telefoneResidencial) {
		this.telefoneResidencial = telefoneResidencial;
	}

	public Email getEmailInstitucional() {
		if(emailInstitucional==null){
			for(Email email :getListaEmails()){
				if(email.getTipo().equals(TipoEmail.INSTITUCIONAL)){
					emailInstitucional= email;
				}
			}
		}
		return emailInstitucional;
	}

	public void setEmailInstitucional(Email emailInstitucional) {
		this.emailInstitucional = emailInstitucional;
	}

	public Email getEmailProfissional() {
		return emailProfissional;
	}

	public void setEmailProfissional(Email emailProfissional) {
		this.emailProfissional = emailProfissional;
	}
	

}
